/**
 * @节流 一段时间内只能执行一次
 * @param {Function} callback 
 * @param {Number} timeout 1000ms
 * @returns {Function}
 */
function Throttle(callback, timeout = 1000) {
    let status = true
    return function (...arg) {
        if (status) {
            const result = callback.call(this, ...arg);
            setTimeout(() => {
                status = true;
            }, timeout)
            return result;
        }
        status = false;
    }
}
/**
 * @防抖 一段时间后执行一次
 * @param {Function} callback 
 * @param {Number} timeout 1000ms
 * @returns {Function}
 */
function Debounce(callback, timeout = 1000) {
    let timer = null
    return function (...arg) {
        clearTimeout(timer);
        timer = setTimeout(() => {
            callback.call(this, ...arg)
        }, timeout)
    }
}


export {
    Throttle,
    Debounce
}